//
//  RollToll.m
//  Roll Ball1.1.1
//
//  Created by Cui Luhai on 10-9-26.
//  Copyright 2010 China Academy of Art. All rights reserved.
//

#import "HunterTool.h"
#import "HunterConst.h"


@implementation HunterTool

/**
 * get random int from {0,1,..,range-1}
 */
+ (int) randomInt : (const int) range{
	srandom(time(NULL)+random());
	return random() % range;
}

/**
 * get different random int array from {0,1,..,range-1}
 */
+ (NSMutableArray *) randomIntArray:(const int) range count:(const int) cnt{
	int source[range];
	for (int i = 0; i < range; i++) {
		source[i]=i;
	}
	
	NSMutableArray *result = [[NSMutableArray alloc] init];
	int sourceSize = range;
	for (int i = 0 ; i < cnt; i++) {
		int index = [HunterTool randomInt:sourceSize];
		//add
		[result addObject:[NSNumber numberWithInt:source[index]]];
		//swap used source
		source[index] = source[sourceSize-1];
		sourceSize--;
	}
		 
	return result;
}
+ (int) randomSign{
    int flag = [HunterTool randomInt:2];
    if (flag == 0) {
        return 1;
    }else {
        return -1;
    }

}

+ (NSString *) numberFormat:(int) number{
    NSString *format = @"0%d";
    if (number > 100) {
        format = @"%d";
    }else if (number < 10) {
        format = @"00%d";
    }
    
    return format;
}
@end
